package com.qianfeng.day11.service;


import com.qianfeng.day11.dao.PriceDAO;
import com.qianfeng.day11.entity.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class PriceService {
    @Resource
    private PriceDAO priceDAO;

    //获取计算后的价格
    public Integer getPrice(Integer id,Integer[] property1,Integer[]property3){
        Double price = 0.0;
        //第一步权重
        List<BasicSituation> bs = priceDAO.findBSIF(id);
        for (BasicSituation bsif : bs) {
            List<BasicSituationInfo> bsList = bsif.getBsList();
            for (BasicSituationInfo sonBslist : bsList) {
                for (Integer integer : property1) {
                    if(integer == sonBslist.getId()){
                        price = price + sonBslist.getWeights();
                    }
                }
            }
        }
        //第三步和第一步的权重之和
        List<WearDegree> wd = priceDAO.findWD();
        for (WearDegree wearDegree : wd) {
            List<WearDegreeInfo> wdiList = wearDegree.getWdList();
            for (WearDegreeInfo wearDegreeInfo : wdiList) {
                for (Integer integer : property3) {
                    if(integer == wearDegreeInfo.getId()){
                        price = price + wearDegreeInfo.getWeights();
                    }
                }
            }
        }

        Phone phone = priceDAO.findPrice(id);
        Double priceEnd1 = phone.getPrice() * (1-price);
        int priceInt = priceEnd1.intValue();
        Integer priceEnd = Integer.valueOf(priceInt);
        return priceEnd;
    }
    //获取手机名称
    public String getPhoneName(Integer id){
        Phone phone = priceDAO.findPrice(id);
        String mobileName = phone.getName();
        return mobileName;
    }

    //获取手机的图片
    public String getPhoneImg(Integer id){
        Phone phone = priceDAO.findPrice(id);
        String img = phone.getImg();
        return img;
    }

}
